'''
Desc: 实现豌豆射手类
Author: 陈爱国
Date: 2024-08-24 09:00:30
'''
import pygame

class Peashooter(pygame.sprite.Sprite):
    def __init__(self):
        # 调用父类构造方法
        super(Peashooter, self).__init__()
        # 图片
        self.image = pygame.image.load('material/images/Peashooter_00.png').convert_alpha()
        # 图片序列，用于产生动画
        self.images = [pygame.image.load('material/images/Peashooter_{:02d}.png'.format(i)).convert_alpha() for i in range(13)]
        # 图片的矩形区域
        self.rect = self.images[0].get_rect()
        # 图片top
        self.rect.top = 100
        # 图片left
        self.rect.left = 250
        # 血量
        self.energy = 3 * 15
        # 存储碰到的僵尸
        self.zombies = set()


    def update(self, *args):
        self.image = self.images[args[0] % len(self.images)]

        if self.energy <= 0:
            # 坚果消失
            self.kill()
            # 挡住的僵尸状态改变
            for zombie in self.zombies:
                zombie.isMeetWallNut = False